import { strict as assert } from 'node:assert';
import { scheduler } from 'node:timers/promises';

import { describe, it, beforeAll, afterAll } from 'vitest';

import mm, { type MockClusterApplication } from '../src/index.ts';
import { getFixtures } from './helper.ts';

// FIXME: nodejs.SyntaxError: Invalid or unexpected token, --import=tsx/esm is not supported on worker_threads mode
describe.skip('work on startMode=worker_threads', () => {
  let app: MockClusterApplication;
  beforeAll(async () => {
    app = mm.cluster({
      baseDir: getFixtures('demo'),
      cache: false,
      coverage: false,
      startMode: 'worker_threads',
    });
    // app.debug();
    await app.ready();
  });
  afterAll(() => app.close());

  it('should have members', async () => {
    assert.equal(app.callback(), app);
    assert.equal(app.listen(), app);
    await app.ready();
    assert(app.process);
  });

  it('should listen on port', async () => {
    await scheduler.wait(3000);
    app.expect('stdout', /egg started on http:\/\/127.0.0.1:17\d{3}/);
  });
});
